// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ArmControlAgentSimulator.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Test.Robotics.Manipulation
{
    using System;
    using System.Runtime.Serialization;
    using Microsoft.Robotics.Hardware.KukaLBR;
    using Microsoft.Robotics.Hardware.Runtime;
    using Microsoft.Robotics.Manipulation;
    using Microsoft.Robotics.Manipulation.Runtime;
    using Microsoft.Robotics.Numerics;
    using Microsoft.Robotics.Runtime;
    using Test.Robotics.Hardware.KukaLBR.KukaLBR4Tests;

        /// <summary>
    /// Differs from  "production" manipulatorAgent in that it does not drive any hardware
    /// but instead uses a a managed simulator FRI
    /// </summary>
    [DataContract]
    public class ArmControlAgentSimulator : KukaLBRControlAgent
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ManipulationAgentSimulator" /> class
        /// </summary>
        /// <param name="name">The name</param>
        /// <param name="producer">heartbeat generator</param>
        /// <param name="maxLinearVelocityInMetersPerSec"> Maximum Cartesian linear velocity of tool control point in m/s. </param>
        /// <param name="maxAngularVelocityInRadPerSec"> Maximum Cartesian angular velocity of tool control point in rad/s. </param>
        /// <param name="maxJointVelocityRadPerSec">Maximum joint velocity for arm movement in radians per sec</param>
        /// <param name="jointMotionDurationInCycles"> Duration in FRI cycles of a single joint motion. </param>
        /// <param name="useKrl"> Indicates whether or not to use KRL to generate motions. </param>
        public ArmControlAgentSimulator(
            string name,
            IProducer<TimerMessage> producer,
            double maxLinearVelocityInMetersPerSec,
            double maxAngularVelocityInRadPerSec,
            double maxJointVelocityRadPerSec,
            bool useKrlMotionCommands,
            double jointMotionDurationInCycles,
            RegionAccessibilityChecker accessibilityChecker = null)
            : base(name,
                   producer,
                   maxLinearVelocityInMetersPerSec,
                   maxAngularVelocityInRadPerSec,
                   maxJointVelocityRadPerSec,
                   useKrlMotionCommands,
                   jointMotionDurationInCycles,
                   accessibilityChecker)
        {
        }

        /// <summary>
        /// Called when the agent is about to start running
        /// </summary>
        public override void OnActivated()
        {
            base.ArmControl = new ArmControlKuka(new FriSimulator());
            base.OnActivated();
        }
    }
}
